﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ECare.Client.templates;
using ECare.BUS;

namespace ECare.Client.frms
{
    public partial class frmLogin : frmNull
    {
        public frmLogin()
        {
            InitializeComponent();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
            {
                this.errorProvider1.SetError(this.txtUserName, "empty?");
                return;
            }
            else
            {
                this.errorProvider1.SetError(this.txtUserName, string.Empty);
            }
            if (string.IsNullOrEmpty(this.txtPassword.Text.Trim()))
            {
                this.errorProvider1.SetError(this.txtPassword, "empty?");
                return;
            }
            else
            {
                this.errorProvider1.SetError(this.txtPassword, string.Empty);
            }
            var newuser = new UserInfo
            {
    
                UserLoginName = this.txtUserName.Text,
                UserPassword = this.txtPassword.Text,
            };
            //
            bool userflag = UserInfoHelper.CheckUser(newuser);
            if (userflag)
            {
                this.DialogResult = DialogResult.OK;

                ApplicationData.CurrentUserInfo = newuser;
                ApplicationData.IsAdjustment = false;//只要重新登录就是没有矫正
            }
            else
            {
                this.label4.Text = "用户名或密码不正确,或者帐户未激活，请重新输入";
                return;
            }
            

        }
    }
}
